package top.withu.gaof.freehope.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import net.bytebuddy.asm.Advice.This;
import top.withu.gaof.freehope.annotate.LogProps;
import top.withu.gaof.freehope.annotate.PassCheck;
import top.withu.gaof.freehope.model.User;
import top.withu.gaof.freehope.service.impl.UserServiceImpl;

/**
 * @author Gaofan
 * @date 2019年4月23日 上午10:55:47
 * @describe
 */
@RestController
@Api("用户模块")
@RequestMapping("/sys")
public class UserController {
	
	private Logger logger = LoggerFactory.getLogger(This.class);

	@Autowired
	private UserServiceImpl userServiceImpl;

	@PostMapping("/register")
	@PassCheck
	@ApiOperation(value = "用户注册", notes = "用于用户注册(管理员操作)", tags = "user module")
	public User register(@RequestBody User user) {
		return userServiceImpl.createUser(user);
	}

	@PostMapping("/login")
	@LogProps(apiId = "FH001")
	@ApiImplicitParams(value = {
			@ApiImplicitParam(paramType = "header", value = "Authorization", name = HttpHeaders.AUTHORIZATION, dataType = "String") })
	@ApiOperation(value = "用户登录", notes = "用户密码登录", tags = "user module")
	public String login(@RequestParam String userName, @RequestParam String password) {
		logger.error("开始打印日志，参数{}",userName);
		logger.error("打印参数完毕");
		return userServiceImpl.getStr();
	}
	

}
